package MyTCP;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class MyThread extends Thread{

    private final Socket socket;
    public MyThread(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream inputStream = socket.getInputStream();
            DataInputStream dataInputStream = new DataInputStream(inputStream);
            while (true) {
                try {
                    String s = dataInputStream.readUTF();
                    System.out.println(s);

                } catch (Exception e) {
                    System.out.println(socket.getRemoteSocketAddress() + "已下线了!!!");
                    dataInputStream.close();
                    inputStream.close();
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
